<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
com.jxtti.model.User userInfo = com.jxtti.utils.AuthUtil.getUserInfo(request);
String orgId=null;
if(userInfo.getDistrictId()==null || userInfo.getDistrictId().equals("0")){ //非超管
	orgId=userInfo.getOrgId().toString();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>咨询留言</title>
		<%@ include file="../../common/Admin-list.jsp"%>  	
		<link rel="stylesheet" type="text/css" href="<%=basePath %>easyui/themes/gray/easyui.css"/>  
		<link rel="stylesheet" type="text/css" href="<%=basePath %>easyui/themes/icon.css"/>   
		<script type="text/javascript" src="<%=basePath %>JS/jquery/jquery-1.7.1.min.js"></script>     
		<script type="text/javascript" src="<%=basePath %>easyui/jquery.easyui.min.js"></script>
		
		<script type="text/javascript" src="<%=bpath %>Scripts/common/common.js"></script> 
		<link rel="stylesheet" type="text/css" href="<%=basePath %>Themes/default/css/jquery.datetimepicker.css"/>    
		<script type="text/javascript" src="<%=basePath %>Scripts/jquery/jquery.datetimepicker.js"></script>
	
	
 		<script type="text/javascript">
			$(function(){
				if(<%=orgId %>!=null){ //是否管理员
					$("#orgId").combotree("setValue",<%=orgId %>);	
					$("#orgId").combotree('disable');
				}
				
				$('#dataGridSys').datagrid({		
					height:'505',
					width:'100%',
					rownumbers:true,//设置为true将显示行数					
					striped:true, //设置为true将交替显示行背景
					fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
					animate:true,
					collapsible:true,
					idField:'id',//id字段
					pagination : true,//分页控件
					pageSize : 10,
				    pageList : [10, 20, 30],
				    url : '../advisoryMsgController/listData.json',
					loadMsg : '数据装载中......',
					singleSelect : true,//设置为 true，则只允许选中一行						
					columns:[[					          	
								{field:'id',hidden:true,editor:{type:'text'}},
								{field:'title',title:'主题',width:100,align:'left',editor:{type:'text'},
									//预览
									formatter:function(value,row,index){										
										var url="/SiteIndex/adviceView.htm?id="+encode64((row.id).toString())+'&preview=yes';									
										return	html='<a href="<%=basePath %>'+url+'" target="_blank" ><img src="<%=basePath %>pages/Admin/Images/search.gif" title="点击预览" style="margin-bottom:-3px"> &nbsp;</a>'+value;					   
									}	
								},
								{field:'typeId',title:'类型',width:30,align:'center',editor:{type:'text'},
									formatter:function(value,row,index){
										if(value=='0'){
												return "咨询留言";
											}else{
												return "污染投诉";
										}
									}								
								},								
								{field:'searchId',hidden:true,title:'查询号码',width:50,align:'center',editor:{type:'text'}},
								{field:'states',title:'状态',width:30,align:'center',editor:{type:'text'},
									formatter:function(value,row,index){
										if(value=='0'){
											return "<font color=\"blue\" >待回复</font>";
										}else if(value=='1'){
											return "<font color=\"#9ACD32\" >已分配 </font>";
										}else if(value=='2'){
											return "<font color=\"#999\" >已回复</font>";
										}
									}								
								},								
								{field:'ad_name',title:'咨询人',width:30,align:'center',editor:{type:'text'}},																
								{field:'is_publish_ad',title:'公开',width:20,align:'center',editor:{type:'text'},
									formatter:function(value,row,index){
										if(value=='1'){
												return "√";
											}else{
												return "";
										}
									}
								},				
								{field:'createTime',title:'咨询时间',width:40,align:'center',editor:{type:'text'}},									
								{field:'task_org_id',hidden:true,width:40,align:'center',editor:{type:'text'}},	
								{field:'task_org_name',title:'所属部门',width:40,align:'left',editor:{type:'text'}},
								{field:'reply_org_id',hidden:true,width:40,align:'center',editor:{type:'text'}},	
								{field:'reply_org_name',title:'回复部门',width:40,align:'left',editor:{type:'text'}},
								{field:'reply_time',title:'回复时间',width:40,align:'center',editor:{type:'text'},
									formatter:function(value,row,index){  
										if(row.states!=2){
											var days=GetDateDiff(row.createTime);
											if(days>=15){
												return "距今<font color=\"red\">"+days+"</font>天"
											}else{
												return value;
											}											
										}else {
											return value;
										}      
	                        		}	
								},	
								
								{field:'opt',title:'操作',width:50,align:'left',  
				                    formatter:function(value,rec,index){			
				                    	
				                    	var edit='<a title="处理" onclick="edit(\''+ rec.id + '\')"  href="#">'+
				                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;';
				                    			
				                    			
				                        var dele='<a title="删除" onclick="del(\''+ rec.id +'\')"  href="#">'+
				                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';                   
				                       
				                        if(<%=orgId %>!=null){ //是否管理员		
				                        	dele='';
				                        }
				                        
				                        if(rec.states==2){
				                        	return edit+dele;  
				                        }else{
				                        	return edit+dele;  
				                        }                        
				                        
				                    }  
				                 }								
					        ]]	
				});	
			})
			
			function GetDateDiff(startDate)  {  
			    var startTime = new Date(Date.parse(startDate.replace(/-/g,   "/"))).getTime();     
			    var endTime = new Date().getTime(); 			   
			    var dates = parseInt(Math.abs((startTime - endTime))/(1000*60*60*24));     
			    return  dates;    
			}
			
			function edit(index){  //编辑   
				art.dialog.open('../advisoryMsgController/updateInterface.htm?opType=edit&id='+index,{
					title: '',
					id:'editDialog',
					lock:true,
				  	width: '90%',
				    height: '90%'												   												   
				});
          	}
			
			function del(index){  //删除操作
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该垃圾留言？',
				    ok: function () {				    	
				    	$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../advisoryMsgController/delete.json',
							data:{id:index,delSub:true},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('删除成功！');
									window.location.reload();  
								}else{
									art.dialog.alert('删除失败，请联系管理员！');
								}
							}
						});
				    },
				    cancelVal: '取消',
				    cancel: true 
				});				
          	}
		
			
		</script>	
	</head>
	<body>
		<div>			
			<table id="dataGridSys"  style="width: 100%;"  type="dataGrid"	data-options="toolbar:'#toolBar'"></table>
			<div id="toolBar" style="height: auto;padding:0px;">
				<!--表单  搜索栏-->
				<div id="filter" class="module">					
					<ul> 		
						<li>
							<label>时间：</label>							
	        				<input type="text" value="" id="timestart" class="inputdate"/>										
						</li>							
						<li>
							<label>-&nbsp;</label>
							<input type="text" value="" id="timeend" class="inputdate"/>						
						</li>	
						<li>
							<label>主题：</label>
							<input type="text" value="" id="title" style="width:200px;"/>						
						</li>	
						<li style="margin-right:300px;">
							<label>分配部门：</label>
							<select id="orgId" name="orgId" class="easyui-combotree" multiple style="width:250px;"   
        							data-options="url:'../district/findByPidAll.json',panelHeight:245"></select>						
						</li>
						<li>							
							<label>类型：</label>							
	        				<select name="typeId" id="typeId" style="width:150px;">
	        					 <option value="" selected="selected">请选择</option>
					             <option value="0">&nbsp;&nbsp;&nbsp;&nbsp;咨询留言</option>
					             <option value="1">&nbsp;&nbsp;&nbsp;&nbsp;污染投诉</option>
	        				</select>										
						</li>
						<li>
							<label>状态：</label>							
	        				<select name="states" id="states" style="width:150px;">
	        					 <option value="" selected="selected">请选择</option>
					             <option value="0">&nbsp;&nbsp;&nbsp;&nbsp;待回复</option>
					             <option value="1">&nbsp;&nbsp;&nbsp;&nbsp;已分配</option>
					             <option value="2">&nbsp;&nbsp;&nbsp;&nbsp;已回复</option>					              
	        				</select>										
						</li>
						<li style="margin-right:250px;">
							&nbsp;&nbsp;&nbsp;&nbsp;
							 <input id="is_publish_ad" type="checkbox" name="is_publish_ad" checked="checked" value="1"  style="width:10px;vertical-align:middle;" />
	                	 	 <label for="is_publish_ad" style="margin-right:8px;">公开显示</label>
						</li>
						
						<li>
							<input type="button" class="btn btn-blue-h20-w2" value="查询" onclick="searchList()" />
						</li>					
					</ul>
					<div class="clear"></div>
				</div>
				<!--表单  列表栏-->
				<div class="list module">
					<div class="hd">
						<h2 class="t">数据列表</h2>
						<span class="handle4filter" title="显示/隐藏查询条件"></span>
					</div>
					<div class="bd">
						<div id="toolbar">
							<ul id="buttonPlace">
								<li>
									<a href="javascript:refresh()" class="icon reload"  hideFocus="false"><span class = "glyphicon glyphicon-edit" style="display:in-line"></span>刷新</a>
								</li> 		
							</ul>
						</div>
					</div>
				</div>
			
			</div>
			
		</div>
	<script type="text/javascript">	
	$('#timestart').datetimepicker({		
		maxDate : 0 ,  //'new Date()'		
		format:'Y-m-d',
		lang:'ch',
		timepicker:false
	});	
	
	$('#timeend').datetimepicker({		
		maxDate : 0 ,  //'new Date()'
		format:'Y-m-d',
		lang:'ch',
		timepicker:false,			
		onShow:function( ct ){				
			this.setOptions({								
				minDate:$('#timestart').val()?$('#timestart').val():false,formatDate:'Y-m-d'						
			});			  
		}		
	});		
	
	
	function searchList() {
		var queryParams = $('#dataGridSys').datagrid('options').queryParams;			
		queryParams.startTime = $('#timestart').val();
		queryParams.endTime = $('#timeend').val();
		queryParams.title =$('#title').val();//主题			
		queryParams.task_org_id=$("#orgId").combotree("getValues").join(',');
		queryParams.typeId =$('#typeId').val();
		queryParams.states =$('#states').val();
		if($('#is_publish_ad').is(':checked')) {
			queryParams.is_publish_ad =$('#is_publish_ad').val();//是否公开
		}else{
			delete queryParams.is_publish_ad;
		}
		$('#dataGridSys').datagrid('load');
		$('#dataGridSys').datagrid('clearSelections');
	}
	
	$(function() {
		if($('#timestart').val()==""){			
			var d = new Date(); //获取今天日期
			d.setDate(d.getDate() - 90);				
			var mon=d.getMonth()+1;
			var day=d.getDate();			
			var str = d.getFullYear()+"-"+(mon<10 ? "0"+ mon : mon)+"-"+(day<10?"0"+day:day);				
			$('#timestart').val(str);			
		}
		
		if($('#timeend').val()==""){
			var d = new Date();
			var mon=d.getMonth()+1;
			var day=d.getDate();
			var str = d.getFullYear()+"-"+(mon<10 ? "0"+ mon : mon)+"-"+(day<10?"0"+day:day);
			$('#timeend').val(str);			
		}
	});
	
	</script>
	</body>
</html>